﻿namespace SharpStockLib.Fin
{
    /// <summary>
    /// Sectors listed by FinViz or Yahoo (global, not only S&P 500 or NYSE)
    /// </summary>
    public enum Sector
    {
        Basic_Materials,
        Conglomerates,
        Consumer_Goods,
        Financial,
        Healthcare,
        Industrial_Goods,
        Services,
        Technology,
        Utilities,
        Unknown
    }

    /// <summary>
    /// Official sectors of the S&P 500, as described by Standard & Poor's
    /// </summary>
    public enum SectorSP
    {
        Materials,
        Energy,
        Consumer_Discretionary,
        Financials,
        Healthcare,
        Industrials,
        Consumer_Staples,
        Utilities,
        Info_Tech,
        Telecom_Services
    }

    /// <summary>
    /// Official sectors of the NYSE, as described by the NYSE itself
    /// </summary>
    public enum SectorNYSE
    {
        Oil_Gas,
        Technology,
        Industrials,
        Consumer_Goods,
        Telecommunications,
        Health_Care,
        Financials,
        Basic_Materials,
        Consumer_Services,
        Utilities,
        Unknown
    }

    public class SectorMapper
    {
        /// <summary>
        /// Basic helper to parse a sector name from the NYSE components list into the appropriate SectorNYSE enum value.
        /// </summary>
        /// <param name="nyseSectorName">The string to parse, as read from the NYSE list of components (as found at http://www.nyse.com/indexes/nyaindex.csv )</param>
        /// <returns>The corresponding value from the SectorNYSE enum.</returns>
        public static SectorNYSE GetSectorFromNYSE(string nyseSectorName)
        {
            switch (nyseSectorName.ToLower())
            {
                case "oil & gas":
                    return SectorNYSE.Oil_Gas;
                case "technology":
                    return SectorNYSE.Technology;
                case "industrials":
                    return SectorNYSE.Industrials;
                case "consumer goods":
                    return SectorNYSE.Consumer_Goods;
                case "telecommunications":
                    return SectorNYSE.Telecommunications;
                case "health care":
                    return SectorNYSE.Health_Care;
                case "financials":
                    return SectorNYSE.Financials;
                case "basic materials":
                    return SectorNYSE.Basic_Materials;
                case "consumer services":
                    return SectorNYSE.Consumer_Services;
                case "utilities":
                    return SectorNYSE.Utilities;

                default:
                    return SectorNYSE.Unknown;
            }
        }
    }
}
